#!/bin/bash
trap 'echo Abort ; exit 1' ERR
err() { echo "Error. $@ not set."; exit 1; }
. varlist
[ -z "$SOURCE_DIR" ] && err SOURCE_DIR
[ -z "$BUILD_DIR" ] && err BUILD_DIR
[ -z "$GCC" ] && err GCC
[ -z "$HOST" ] && err HOST
[ -z "$TARGET" ] && err TARGET
[ -z "$ARM_ROOT_DIR" ] && err ARM_ROOT_DIR
[ -z "$STATIC_LIB_DIR" ] && err STATIC_LIB_DIR

echo Build gcc1.
[ -f $ARM_ROOT_DIR/.${GCC}_1 ] && exit 0

export PATH=$PATH:$ARM_ROOT_DIR/usr/bin/ #:$ARM_ROOT_DIR/usr/$TARGET/bin/
rm $BUILD_DIR/${GCC}_1 -rf
mkdir $BUILD_DIR/${GCC}_1
cd $BUILD_DIR/${GCC}_1

$SOURCE_DIR/$GCC/configure --prefix=/usr \
	--build=$HOST --host=$HOST --target=$TARGET \
	--with-sysroot=$ARM_ROOT_DIR \
	--with-gmp=$STATIC_LIB_DIR --with-mpfr=$STATIC_LIB_DIR \
	--without-headers --with-newlib --disable-multilib --disable-nls \
	--disable-decimal-float --disable-libgomp --disable-libmudflap \
	--disable-libssp --disable-shared --disable-threads --enable-long-long \
	--enable-languages=c --with-float=soft --with-cpu=arm926ej-s
set -x
make
make DESTDIR=$ARM_ROOT_DIR install
touch $ARM_ROOT_DIR/.${GCC}_1
